# GNAFU - "Ground, Navy and Air Fuck-Up" real-time strategy game
# Copyright (C) 2008-2009 k0wax <k0waxk0wax@gmail.com>
#
# This file is part of GNAFU.
#
# GNAFU is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNAFU is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNAFU.  If not, see <http://www.gnu.org/licenses/>.

"""Main"""
from __future__ import division, absolute_import
import pyglet
from pyglet import gl
from src import game

def init():
    """init game's infrastructure.
    """
    global win
    from src.win import GameWindow
    win = GameWindow()
    game.init(_win=win)

def create_game():
    print 'create_game()'
    init()
    game.create()

def load_game(filename):
    print 'load_game()'
    init()
    game.load()
    

def run():
    """Do final manipulations and fire the mainloop.
    """
    pyglet.clock.schedule(game.update)
    win.on_draw = game.draw
    win.set_visible()
    gl.glEnable(gl.GL_BLEND)
    gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA)
    pyglet.app.run()
